import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;


public class MouseClick implements MouseListener {
	
	ControlPanel control;
	RobotPanel robot;
	ButtonListener bl;
	
	boolean addRobotEnd = false;
	Robot current_robot;
	
	MouseClick(RobotPanel rob, ControlPanel con, ButtonListener b){
		control = con;
		robot = rob;
		bl=b;
	}
	
	@Override
	public void mouseClicked(MouseEvent e) {
		if(control.add_block && !addRobotEnd){
			robot.addBlock(new Block(e.getX(),e.getY(), bl.getBlockSize()));
			robot.repaint();
		}
		else if(control.add_robot && !addRobotEnd)
		{
			  double start_x = e.getX();
			  double start_y = e.getY();
		      current_robot = new Robot(start_x, start_y);
			  robot.addRobot(current_robot);
			  robot.repaint();
		      addRobotEnd = true;
		      control.setVisible(false);
		}
		else if(addRobotEnd)
		{
			current_robot.setEndX(e.getX());
			current_robot.setEndY(e.getY());
			robot.repaint();
			addRobotEnd = false;
			control.setVisible(true);
		}
		
	}

	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

}
